<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   主题：请问计算pearson correlation时，cor()和cor.test()有什么区别吗?  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript">
   MathJax.Hub.Config({elements: ["bbpress-forums"]});
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://cos.name/cn/topic/16075/",
                  host: "http://cos.name",
                  prePath: "http://cos.name",
                  scheme: "http",
                  pathBase: "http://cos.name/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466453020: Accept with keywords: (title(0.2):区别,主题,论坛,计算,时, topn(0.166666666667):RSS订阅,软件应用,区别,菜鸟,指教,帖子,R语言,作者,会员,行数,数据格式,用户名,结果,主站,新鲜事,计算,数据,版权所有,菜单,问题,密码,总计,模板,版主,代码,主题,程序,普通,论坛,讨论区).-->
 </head>
 <body class="topic bbpress single single-topic postid-16075 single-author sidebar" onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    主题：请问计算pearson correlation时，cor()和cor.test()有什么区别吗?
   </h1>
  </div>
  <div class="container" id="xmain">
   <div class="hfeed site" id="page">
    <header class="site-header" id="masthead" role="banner">
     <div id="cos-logo">
      <a href="http://cos.name/cn">
       <img src="http://cos.name/cn/wp-content/themes/COS-forest/images/headers/cos-logo.png"/>
      </a>
     </div>
     <div class="navbar" id="navbar">
      <nav class="navigation main-navigation" id="site-navigation" role="navigation">
       <h3 class="menu-toggle">
        菜单
       </h3>
       <div class="menu-%e8%8f%9c%e5%8d%951-container">
        <ul class="nav-menu" id="menu-%e8%8f%9c%e5%8d%951">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-407772" id="menu-item-407772">
          <a href="http://cos.name/cn/">
           论坛首页
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-407773" id="menu-item-407773">
          <a href="http://cos.name/cn/forums/">
           讨论区
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-407774" id="menu-item-407774">
          <a href="http://cos.name/cn/wp-login.php?action=register">
           注册
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-407819" id="menu-item-407819">
          <a href="http://cos.name/">
           主站
          </a>
         </li>
        </ul>
       </div>
      </nav>
      <!-- #site-navigation -->
     </div>
     <!-- #navbar -->
    </header>
    <!-- #masthead -->
    <div class="site-main" id="main">
     <div class="content-area" id="primary">
      <div class="site-content" id="content" role="main">
       <article class="post-16075 topic type-topic status-publish hentry" id="post-16075">
        <header class="entry-header">
         <h1 class="entry-title">
          请问计算pearson correlation时，cor()和cor.test()有什么区别吗?
         </h1>
        </header>
        <!-- .entry-header -->
        <div class="entry-content">
         <div id="bbpress-forums">
          <div class="bbp-breadcrumb">
           <p>
            <a class="bbp-breadcrumb-home" href="http://cos.name/cn/">
             COS论坛 | 统计之都
            </a>
            <span class="bbp-breadcrumb-sep">
             ›
            </span>
            <a class="bbp-breadcrumb-root" href="http://cos.name/cn/forums/">
             讨论区
            </a>
            <span class="bbp-breadcrumb-sep">
             ›
            </span>
            <a class="bbp-breadcrumb-forum" href="http://cos.name/cn/forum/software/">
             软件应用
            </a>
            <span class="bbp-breadcrumb-sep">
             ›
            </span>
            <a class="bbp-breadcrumb-forum" href="http://cos.name/cn/forum/software/r-language/">
             S-Plus &amp; R语言
            </a>
            <span class="bbp-breadcrumb-sep">
             ›
            </span>
            <span class="bbp-breadcrumb-current">
             请问计算pearson correlation时，cor()和cor.test()有什么区别吗?
            </span>
           </p>
          </div>
          <div class="bbp-template-notice info">
           <p class="bbp-topic-description">
            该主题包含 12 条回复，4个帖子，最后由
            <a class="bbp-author-avatar" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
             <img src="http://sdn.geekzu.org/avatar/cae300102b5a6723bd2cc927d512ac7c?s=14&amp;d=monsterid&amp;r=g"/>
            </a>
            <a class="bbp-author-name" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
             camelbbs
            </a>
            在
            <a href="http://cos.name/cn/topic/16075/#post-276033" title="回复：请问计算pearson correlation时，cor()和cor.test()有什么区别吗?">
             6 年, 10 月 之前
            </a>
            更新。
           </p>
          </div>
          <div class="bbp-pagination">
           <div class="bbp-pagination-count">
            查看 13 个帖子 - 1 到 13（总计 13 个）
           </div>
           <div class="bbp-pagination-links">
           </div>
          </div>
          <ul class="forums bbp-replies" id="topic-16075-replies">
           <li class="bbp-header">
            <div class="bbp-reply-author">
             作者
            </div>
            <!-- .bbp-reply-author -->
            <div class="bbp-reply-content">
             帖子
            </div>
            <!-- .bbp-reply-content -->
           </li>
           <!-- .bbp-header -->
           <li class="bbp-body">
            <div class="bbp-reply-header" id="post-16075">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2009年8月11日 上午9:49
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/16075/#post-16075">
               1 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-16075 -->
            <div class="odd bbp-parent-forum-999 bbp-parent-topic-16075 bbp-reply-position-1 user-id-101408 topic-author post-16075 topic type-topic status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               <img src="http://sdn.geekzu.org/avatar/cae300102b5a6723bd2cc927d512ac7c?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               camelbbs
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               请问计算pearson correlation时，cor()和cor.test()有什么区别吗?
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-275747">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2009年8月11日 下午6:01
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/16075/#post-275747">
               2 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-275747 -->
            <div class="even bbp-parent-forum-999 bbp-parent-topic-16075 bbp-reply-position-2 user-id-81803 post-275747 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/81803/" rel="nofollow" title="查看lanfeng的档案">
               <img src="http://sdn.geekzu.org/avatar/b31fdd7b3ff8c55baf90ed710e1ed034?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/81803/" rel="nofollow" title="查看lanfeng的档案">
               lanfeng
              </a>
              <br/>
              <div class="bbp-author-role">
               版主
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               你运行一下就知道了，一个只求值，一个是做检验
              </p>
              <pre class="highlight ">x &lt;- c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
y &lt;- c( 2.6,  3.1,  2.5,  5.0,  3.6,  4.0,  5.2,  2.8,  3.8)
cor(x,y)
cor.test(x, y)
</pre>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-275850">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2009年8月12日 下午5:20
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/16075/#post-275850">
               3 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-275850 -->
            <div class="odd bbp-parent-forum-999 bbp-parent-topic-16075 bbp-reply-position-3 user-id-101408 topic-author post-275850 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               <img src="http://sdn.geekzu.org/avatar/cae300102b5a6723bd2cc927d512ac7c?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               camelbbs
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               谢谢蓝枫，
               <br/>
               我还有一个问题，我这有个别人帮我写的程序，是做correlation的，但是要求的数据格式是什么样的呢？谢谢！
              </p>
              <pre class="highlight ">cor_data_order &lt;- function(data) {
        # Pearson correlation of geneX and geneY within the data matrix
        row &lt;- nrow(data)
        rMatrix &lt;- matrix(-1, ncol=4, nrow=((row*(row-1))/2))
        n &lt;- 0
        for(i in 1:(row-1)) {
                for (j in (i+1):row) {
                        n &lt;- (n+1)
                        geneX &lt;- data[i,]
                        geneY &lt;- data[j,]
                        rMatrix[n, 1] &lt;- rownames(data)[i]
                        rMatrix[n, 2] &lt;- rownames(data)[j]
                        rMatrix[n, 3] &lt;- cor.test(geneX, geneY)$estimate
                        rMatrix[n, 4] &lt;- cor.test(geneX, geneY)$p.value
                }
        }
       
        if (identical(all.equal(n, (row*(row-1)/2)), TRUE)) {
                colnames(rMatrix) &lt;- c("geneX", "geneY", "correlation","pvalue")
                frMatrix &lt;- rMatrix[sort.list(as.numeric(rMatrix[,3]),decreasing=TRUE),]
                return(frMatrix)
        }
        else {
                cat(paste("n = ", n, "; nrow = ", (row*(row-1)/2), "\n",sep=""))
        }
}
</pre>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-275852">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2009年8月12日 下午7:56
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/16075/#post-275852">
               4 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-275852 -->
            <div class="even bbp-parent-forum-999 bbp-parent-topic-16075 bbp-reply-position-4 user-id-101408 topic-author post-275852 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               <img src="http://sdn.geekzu.org/avatar/cae300102b5a6723bd2cc927d512ac7c?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               camelbbs
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               我的问题是这样的，有类似这样一组数据，
              </p>
              <pre class="highlight ">&gt; x
    probe   sample1   sample2   sample3   sample4   sample5   sample6   sample7
1 5209108 0.3230395 0.3271732 0.3668815 0.3323442 0.3275477 0.3436931 0.3518626
2 5586848 0.1784362 0.1964064 0.1897725 0.1873856 0.1988175 0.1852349 0.1821880
3 5206267 0.2858441 0.3005623 0.2973683 0.2948403 0.2788130 0.3131182 0.3032633
4 5312872 0.2126801 0.1758581 0.1459777 0.1854299 0.1948218 0.1579538 0.1626862
    sample8   sample9  sample10  sample11  sample12  sample13  sample14
1 0.3378541 0.3466587 0.3563434 0.3392290 0.3490743 0.3319676 0.3268605
2 0.1747993 0.1858949 0.1583964 0.1910472 0.1834229 0.2105563 0.2058629
3 0.2894799 0.2972564 0.3097042 0.2790696 0.3001432 0.2928737 0.2746477
4 0.1978667 0.1701900 0.1755559 0.1906542 0.1673596 0.1646023 0.1926289
   sample15  sample16  sample17  sample18  sample19  sample20  sample21
1 0.3158487 0.3160888 0.3202584 0.3276074 0.3283119 0.3139104 0.3176531
2 0.2120883 0.2371918 0.2113405 0.2038217 0.1989849 0.2208813 0.2208901
3 0.2909840 0.2945929 0.2904993 0.2888500 0.2898802 0.2757683 0.2915066
4 0.1810789 0.1521264 0.1779019 0.1797210 0.1828230 0.1894400 0.1699503
   sample22  sample23  sample24  sample25  sample26
1 0.3215730 0.3277564 0.3131653 0.3312661 0.3109205
2 0.2245201 0.2200054 0.2197569 0.2019280 0.2198725
3 0.2848705 0.2786372 0.2899670 0.2918463 0.2919011
4 0.1690363 0.1736010 0.1771108 0.1749596 0.1773060
</pre>
              <p>
               现在想给这四个probe做correlation分析，用read.table将数据读取之后，行名为probe，列名为sample。
               <br/>
               现在用cor(x)得到的是sample之间的correlation的结果，我如果想得到probe之间correlation的结果，就得把这个矩阵旋转90度才行，我可以用excel来做，但是R有没有更方便的方法，上面是别人给我的程序，但是看不太懂，希望高手指教
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-275858">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2009年8月13日 上午2:54
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/16075/#post-275858">
               5 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-275858 -->
            <div class="odd bbp-parent-forum-999 bbp-parent-topic-16075 bbp-reply-position-5 user-id-81532 post-275858 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/81532/" rel="nofollow" title="查看Ihavenothing的档案">
               <img src="http://sdn.geekzu.org/avatar/f09663fd5fc04bad5e5b09daddb86fe6?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/81532/" rel="nofollow" title="查看Ihavenothing的档案">
               Ihavenothing
              </a>
              <br/>
              <div class="bbp-author-role">
               站长
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               转置用t()，程序是cor(t(x))。
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-275896">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2009年8月13日 下午3:16
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/16075/#post-275896">
               6 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-275896 -->
            <div class="even bbp-parent-forum-999 bbp-parent-topic-16075 bbp-reply-position-6 user-id-101408 topic-author post-275896 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               <img src="http://sdn.geekzu.org/avatar/cae300102b5a6723bd2cc927d512ac7c?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               camelbbs
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               谢谢，图中是我的数据
              </p>
              <p>
               使用上面的函数cor_data_order(x)之后老是出错：
              </p>
              <pre class="highlight ">Error in rMatrix[n, 3] &lt;- cor.test(geneX, geneY)$estimate : 
  number of items to replace is not a multiple of replacement length
</pre>
              <p>
               郁闷死了
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-275905">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2009年8月14日 上午2:22
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/16075/#post-275905">
               7 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-275905 -->
            <div class="odd bbp-parent-forum-999 bbp-parent-topic-16075 bbp-reply-position-7 user-id-336 post-275905 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/336/" rel="nofollow" title="查看刘思喆的档案">
               <img src="http://sdn.geekzu.org/avatar/6ca0529d22d1bf25a1e5cee3af3456f9?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/336/" rel="nofollow" title="查看刘思喆的档案">
               刘思喆
              </a>
              <br/>
              <div class="bbp-author-role">
               版主
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               R 的脚本容易写，但——你是要做什么呢？或者说 你想把 estimate p.value 怎么放置，想表达什么？
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-275938">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2009年8月14日 下午3:12
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/16075/#post-275938">
               8 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-275938 -->
            <div class="even bbp-parent-forum-999 bbp-parent-topic-16075 bbp-reply-position-8 user-id-101408 topic-author post-275938 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               <img src="http://sdn.geekzu.org/avatar/cae300102b5a6723bd2cc927d512ac7c?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               camelbbs
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               这个是我的数据：
              </p>
              <pre class="highlight ">V1    V2    V3    V4    V5    V6    V7    V8    V9    V10    V11    V12    V13    V14    V15    V16    V17    V18    V19    V20    V21    V22    V23    V24    V25    V26
mmu_miR_700    -0.07    -0.03    0.02    -0.06    0.07    -0.02    0.04    -0.04    0.19    -0.03    -0.06    -0.09    0.16    0.02    0.01    0.01    0.06    0.1    -0.12    -0.07    0.11    -0.02    -0.02    -0.03    -0.06    -0.02
p4352739    -1.52049    -0.961834    -1.11275    -1.53636    -1.39581    -0.458406    -0.975519    -1.01034    -0.514836    -1.10268    -0.850454    -1.04564    -0.56965    -0.787582    1.03805    0.445062    0.996138    0.233415    1.03245    0.13054    1.0832    1.11449    1.1086    1.24943    1.31127    0.791774
p4363109    -2.27327    -2.03811    -1.35    -1.24343    -1.00813    -0.255477    -0.387463    0.00577596    -0.9441    -0.540299    -0.415612    -0.93772    -0.28527    -0.41058    0.780574    0.326526    0.811167    -0.0790327    0.651029    -0.446715    1.22988    1.10172    1.21379    1.40274    0.997862    1.01706
p5136091    -0.481687    -1.36505    -0.281442    0.380456    0.562349    -0.555013    -0.0500013    -0.160981    -0.192816    -0.4126    -0.655563    -0.850933    -0.129232    -0.561256    -0.266073    -0.0645273    -0.65533    0.0338232    0.299843    -0.653168    1.76744    2.29648    0.140562    3.30331    -0.0552576    -0.196023
p5239415    -0.685966    -0.819688    -2.59202    -1.40214    -0.964133    -0.164639    -0.920252    -0.257726    -1.12936    -0.82555    -0.331938    0.0507733    -0.354406    -1.85528    0.307561    0.480994    0.651558    -0.133782    1.39683    0.369889    0.904953    1.13047    0.844956    0.85147    1.04792    1.19538
t6926082    -1.61105    -1.32208    -1.71058    -0.966049    -1.01572    -0.568051    -0.755362    -0.631074    -0.83878    -0.919201    -0.842434    -0.895636    -0.610344    -0.867652    0.740584    0.347356    0.739415    0.0844864    1.02664    0.0583954    1.31539    1.33683    1.09716    1.57393    1.18863    0.975186
</pre>
              <p>
               这个是我想得到的结果：
              </p>
              <pre class="highlight ">&gt; cor_data_order(data)
      geneX         geneY      correlation           pvalue 
            
 [1,] "p4352739"    "t6926082" "0.965661044033223" 
"1.33226762955019e-15"
 [2,] "p4363109"    "t6926082" "0.94233273417543"  
"6.63913368725844e-13"
 [3,] "p4352739"    "p4363109" "0.898957989968256" 
"4.42480718731986e-10"
 [4,] "p5239415"    "t6926082" "0.883656431377926" 
"2.21503193564843e-09"
 [5,] "p4352739"    "p5239415" "0.838250333957843" 
"9.03842727328907e-08"
 [6,] "p4363109"    "p5239415" "0.784941681830309" 
"2.05470887859605e-06"
 [7,] "p5136091"    "t6926082" "0.593999737575809" 
"0.00137702100275416"
 [8,] "p4363109"    "p5136091" "0.555875799859063" 
"0.00319341191384348"
 [9,] "p4352739"    "p5136091" "0.470147801339052" 
"0.0153653401857028" 
[10,] "p5136091"    "p5239415" "0.382155506562416" 
"0.0540251919989716" 
[11,] "mmu_miR_700" "p5136091" "0.096449066550402" 
"0.639281285870928"  
[12,] "mmu_miR_700" "p4363109" "0.0291241027537882"
"0.887687971028281"  
[13,] "mmu_miR_700" "p4352739" "0.00287770597274169"
"0.988868432631662"  
[14,] "mmu_miR_700" "t6926082" "-0.053528395797006"
"0.795091559755513"  
[15,] "mmu_miR_700" "p5239415" "-0.238604796164897"
"0.240449351131640"  
</pre>
              <p>
               代码上面已经写了，现在的问题是运行之后老是出错，这个错误好像是因为数据导入上的问题，请版主帮忙了
               <br/>
               Error in rMatrix[n, 3] &lt;- cor.test(geneX, geneY)$estimate :
               <br/>
               number of items to replace is not a multiple of replacement length
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-275939">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2009年8月14日 下午3:53
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/16075/#post-275939">
               9 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-275939 -->
            <div class="odd bbp-parent-forum-999 bbp-parent-topic-16075 bbp-reply-position-9 user-id-81532 post-275939 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/81532/" rel="nofollow" title="查看Ihavenothing的档案">
               <img src="http://sdn.geekzu.org/avatar/f09663fd5fc04bad5e5b09daddb86fe6?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/81532/" rel="nofollow" title="查看Ihavenothing的档案">
               Ihavenothing
              </a>
              <br/>
              <div class="bbp-author-role">
               站长
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               是程序有点问题，数据读取出来是个data.frame，因此geneX和geneY也是data.frame，把程序中相应的地方改为
              </p>
              <pre class="highlight ">cor.test(as.numeric(geneX),as.numeric(geneY))</pre>
              <p>
               。
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-275942">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2009年8月14日 下午4:26
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/16075/#post-275942">
               10 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-275942 -->
            <div class="even bbp-parent-forum-999 bbp-parent-topic-16075 bbp-reply-position-10 user-id-101408 topic-author post-275942 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               <img src="http://sdn.geekzu.org/avatar/cae300102b5a6723bd2cc927d512ac7c?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               camelbbs
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               Thanks so much. It's OK now.
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-275943">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2009年8月14日 下午5:51
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/16075/#post-275943">
               11 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-275943 -->
            <div class="odd bbp-parent-forum-999 bbp-parent-topic-16075 bbp-reply-position-11 user-id-101408 topic-author post-275943 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               <img src="http://sdn.geekzu.org/avatar/cae300102b5a6723bd2cc927d512ac7c?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               camelbbs
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               我还有一个问题，我的数据其实比上面的要复杂一点，类似这样：
              </p>
              <pre class="highlight ">        sample1    sample2    sample3    sample4    sample5    sample6
group1    5258687    0.24284423    0.262258756    0.247511921    0.240177126    0.19757874    0.20743572
group1    5017477    0.385206387    0.370489086    0.377444681    0.388880066    0.403683162    0.409091484
group1    5178705    0.371949382    0.367252159    0.375043398    0.370942808    0.398738098    0.383472797
group2    4910905    0.119236897    0.123436234    0.123520384    0.124513978    0.122990159    0.123484051
group2    4878392    0.125212652    0.123648862    0.124638447    0.126508815    0.123665777    0.123649197
group2    4535980    0.130353779    0.125152066    0.130775508    0.129140793    0.128049899    0.1274602
group2    4978647    0.134167088    0.129121117    0.131050928    0.130007065    0.127913789    0.128435536
group2    4872246    0.107005107    0.110962072    0.110502934    0.109987348    0.12020089    0.119784765
</pre>
              <p>
               也就是每行数据除了有个名字之外，还属于不同的group，一共有上千个group，全部按顺序放在一个文本里。
              </p>
              <p>
               如果要把每行数据都和其他行做cor.test()，得到的行数就是(row*(row-1))/2，如果row=1800，这个结果就太大了。
               <br/>
               而我只需要在每个group内部做cor.test()，每个group只有几行，所以只需要做这几行的cor.test()即可。
               <br/>
               我是用perl写代码的，所以不知道R如何写这个语句，仅仅将同一个group内部的数据做cor.test()。
              </p>
              <p>
               请指教。
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-275991">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2009年8月16日 上午5:36
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/16075/#post-275991">
               12 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-275991 -->
            <div class="even bbp-parent-forum-999 bbp-parent-topic-16075 bbp-reply-position-12 user-id-336 post-275991 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/336/" rel="nofollow" title="查看刘思喆的档案">
               <img src="http://sdn.geekzu.org/avatar/6ca0529d22d1bf25a1e5cee3af3456f9?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/336/" rel="nofollow" title="查看刘思喆的档案">
               刘思喆
              </a>
              <br/>
              <div class="bbp-author-role">
               版主
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               根据 你的 group 把数据转化为 list，然后 lapply，最后合并结果。
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-276033">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2009年8月17日 下午3:54
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/16075/#post-276033">
               13 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-276033 -->
            <div class="odd bbp-parent-forum-999 bbp-parent-topic-16075 bbp-reply-position-13 user-id-101408 topic-author post-276033 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               <img src="http://sdn.geekzu.org/avatar/cae300102b5a6723bd2cc927d512ac7c?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/101408/" rel="nofollow" title="查看camelbbs的档案">
               camelbbs
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               版主可以写个模板吗，菜鸟不懂，呵呵
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
           </li>
           <!-- .bbp-body -->
           <li class="bbp-footer">
            <div class="bbp-reply-author">
             作者
            </div>
            <div class="bbp-reply-content">
             帖子
            </div>
            <!-- .bbp-reply-content -->
           </li>
           <!-- .bbp-footer -->
          </ul>
          <!-- #topic-16075-replies -->
          <div class="bbp-pagination">
           <div class="bbp-pagination-count">
            查看 13 个帖子 - 1 到 13（总计 13 个）
           </div>
           <div class="bbp-pagination-links">
           </div>
          </div>
          <div class="bbp-no-reply" id="no-reply-16075">
           <div class="bbp-template-notice">
            <p>
             您必须先登录才能回复该主题。
            </p>
           </div>
          </div>
         </div>
        </div>
        <!-- .entry-content -->
        <footer class="entry-meta">
        </footer>
        <!-- .entry-meta -->
       </article>
       <!-- #post -->
       <div class="comments-area" id="comments">
       </div>
       <!-- #comments -->
      </div>
      <!-- #content -->
     </div>
     <!-- #primary -->
     <div class="sidebar-container" id="tertiary" role="complementary">
      <div class="sidebar-inner">
       <div class="widget-area">
        <aside class="widget bbp_widget_login" id="bbp_login_widget-2">
         <h3 class="widget-title">
          登录
         </h3>
         <form action="http://cos.name/cn/wp-login.php" class="bbp-login-form" method="post">
          <fieldset>
           <legend>
            登录
           </legend>
           <div class="bbp-username">
            <label for="user_login">
             用户名:
            </label>
           </div>
           <div class="bbp-password">
            <label for="user_pass">
             密码:
            </label>
           </div>
           <div class="bbp-remember-me">
            <label for="rememberme">
             记住用户名
            </label>
           </div>
           <div class="bbp-submit-wrapper">
            <button class="button submit user-submit" id="user-submit" name="user-submit" tabindex="104" type="submit">
             登录
            </button>
           </div>
           <div class="bbp-login-links">
            <a class="bbp-register-link" href="http://cos.name/cn/wp-login.php?action=register" title="注册">
             注册
            </a>
            <a class="bbp-lostpass-link" href="http://cos.name/cn/wp-login.php?action=lostpassword" title="忘记密码">
             忘记密码
            </a>
           </div>
          </fieldset>
         </form>
        </aside>
        <aside class="widget widget_text" id="text-7">
         <h3 class="widget-title">
          搜索
         </h3>
         <div class="textwidget">
          <form action="http://www.google.com/search" id="bbp-search-form" method="get" onsubmit="Gsitesearch(this)" role="search">
           <div>
           </div>
          </form>
          <form id="bbp-search-form-baidu" onsubmit="g(this)" role="search">
           <div>
           </div>
          </form>
         </div>
        </aside>
        <aside class="widget widget_text" id="text-2">
         <h3 class="widget-title">
          新鲜事
         </h3>
         <div class="textwidget">
          <ul>
           <li>
            <a href="http://cos.name/cn/topics/">
             最新帖子
            </a>
           </li>
           <li>
            <a href="http://cos.name/cn/view/popular/">
             最热门主题
            </a>
           </li>
           <li>
            <a href="http://cos.name/cn/view/no-replies/">
             消灭零回复
            </a>
           </li>
          </ul>
         </div>
        </aside>
        <aside class="widget widget_text" id="text-3">
         <h3 class="widget-title">
          RSS订阅
         </h3>
         <div class="textwidget">
          <ul>
           <li>
            <img src="http://cos.name/wp-includes/images/rss.png"/>
            <a href="http://cos.name/cn/topics/feed/">
             所有主题
            </a>
           </li>
           <li>
            <img src="http://cos.name/wp-includes/images/rss.png"/>
            <a href="http://cos.name/cn/forums/feed/">
             所有帖子
            </a>
           </li>
          </ul>
         </div>
        </aside>
       </div>
       <!-- .widget-area -->
      </div>
      <!-- .sidebar-inner -->
     </div>
     <!-- #tertiary -->
    </div>
    <!-- #main -->
    <footer class="site-footer" id="colophon" role="contentinfo">
     <div class="site-info">
      版权所有 © 2014 统计之都 | 由
      <a href="http://wordpress.org/">
       WordPress
      </a>
      构建 | 主题修改自
      <a href="http://wordpress.org/themes/twentythirteen">
       Twenty Thirteen
      </a>
     </div>
     <!-- .site-info -->
    </footer>
    <!-- #colophon -->
   </div>
   <!-- #page -->
  </div>
 </body>
</html>